package cate.game.event.hero;

import cate.game.event.GameEventListener;
import cate.game.role.Role;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Set;
import java.util.stream.Collectors;

public class HeroPowerChangeListener implements GameEventListener<HeroPowerChangeEvent> {
    @Override
    public void onEvent(HeroPowerChangeEvent gameEvent) {
        Role role = gameEvent.role;
        if(role != null && CollectionUtils.isNotEmpty(gameEvent.heros)){
            Set<String> heroUids = gameEvent.heros.stream().map(v -> v.uid).collect(Collectors.toSet());
            role.getGame().power.markPowerExpire(role, v -> heroUids.contains(v.uid));
            gameEvent.heros.forEach(e -> role.getGame().rank.camps.record(role, e, e.getPower(role.getGame().fight.getPlayBuildContext())));
            role.getGame().pvp.championRace.markDirty(role.getUid());
        }
    }
}
